<template>
  <div class="community-layout-page">
    <div class="community-info">
      <div class="community-name">
        {{ communityInfo.villageName }}
        <span class="community-id">{{ communityId }}</span>
        <span class="item-type" v-if="communityInfo.ifBdggz == '1'">八大高感知场景</span>
        <span class="item-type" v-if="communityInfo.ifSwly === '1'">公众线+商务楼宇</span>
        <span class="item-type" v-if="communityInfo.ifSwly === '2'">商务楼宇</span>
        <span class="item-type" v-if="communityInfo.errNum > 0">任务传图异常</span>
        <!-- <span class="community-type">{{ communityInfo.villageType }}</span> -->
      </div>
      <div class="community-address">地址：{{ communityInfo.villageAddr }}</div>
      <div class="info-line" v-if="showDetail">
        <div class="info-item">
          <div class="info-label">是否联通覆盖</div>
          <div class="info-value">{{ communityInfo.ifLtxq == 1 ? '是':'否' }}</div>
        </div>
        <div class="info-item">
          <div class="info-label">是否千兆小区</div>
          <div class="info-value">{{ communityInfo.ifGg == 1 ? '是':'否' }}</div>
        </div>
      </div>
      <div class="info-line" v-if="showDetail">
        <div class="info-item">
          <div class="info-label">是否全千兆小区</div>
          <div class="info-value">{{ communityInfo.ifAllGg == 1 ? '是':'否' }}</div>
        </div>
        <div class="info-item">
          <div class="info-label">楼宇数</div>
          <div class="info-value">{{ communityInfo.buildNum }}</div>
        </div>
      </div>
      <div class="info-line" v-if="showDetail">
        <div class="info-item">
          <div class="info-label">住户数</div>
          <div class="info-value">{{ communityInfo.userNum }}</div>
        </div>
        <div class="info-item">
          <div class="info-label">宽带用户</div>
          <div class="info-value">{{ communityInfo.kdUser }}</div>
        </div>
      </div>
      <div class="info-line" v-if="showDetail">
        <div class="info-item">
          <div class="info-label">4G覆盖率</div>
          <div class="info-value" v-if="communityInfo.mr4g == null">-</div>
          <div class="info-value" v-else>{{ communityInfo.mr4g }} %</div>
        </div>
        <div class="info-item">
          <div class="info-label">5G覆盖率</div>
          <div class="info-value" v-if="communityInfo.mr5g == null">-</div>
          <div class="info-value" v-else>{{ communityInfo.mr5g }} %</div>
        </div>
      </div>
      <hr>
      <!-- <van-divider style="margin: 4px">小区负责人信息</van-divider> -->
      <!-- <div class="info-line title-line" v-if="showDetail">
          <div class="title-item">岗位类型</div>
          <div class="title-item">姓名</div>
          <div class="title-item">电话</div>
      </div> -->
      <div class="info-line" v-if="communityInfo.khjlName">
          <div class="info-person">客户经理</div>
          <!-- <div class="info-person">{{ communityInfo.khjlOaAcct }}</div> -->
          <div class="info-person">{{ communityInfo.khjlName || '-' }}</div>
          <div class="info-person">{{ communityInfo.khjlPhone || '-' }}</div>
      </div>
      <div class="info-line" v-if="communityInfo.wlfzrName">
        <div class="info-person">网络工程师</div>
        <!-- <div class="info-person">{{ communityInfo.wlfzrOaAcct }}</div> -->
        <div class="info-person">{{ communityInfo.wlfzrName || '-' }}</div>
        <div class="info-person">{{ communityInfo.wlfzrPhone || '-' }}</div>
      </div>
      <div class="info-line" v-if="communityInfo.zjgcsName">
        <div class="info-person">智家工程师</div>
        <!-- <div class="info-person">{{ communityInfo.zjgcsOaAcct }}</div> -->
        <div class="info-person">{{ communityInfo.zjgcsName || '-' }}</div>
        <div class="info-person">{{ communityInfo.zjgcsPhone || '-' }}</div>
      </div>

      <div :class="['community-status', communityInfo.state === '0' ? 'undo' : communityInfo.state === '1' ? 'doing' : 'done' ]">
        {{ communityInfo.state === '0' ? '未完成' : communityInfo.state === '1' ? '进行中' : '已完成' }}
      </div>
    </div>
    <div class="content">
      <router-view :communityInfo="communityInfo" />
    </div>
  </div>
</template>

<script>
import { getCommunityInfo, getCommunityDkRecord } from '@/api/publicline/kdcs'

export default {
  data() {
    return {
      showDetail: true,
      communityInfo: {
        communityName: "北张住宅小区",
        communityId: '10031',
        communityType: '1',
        address: "太原市南中环街19号",
        taskStatus: '1'
      },
    }
  },
  created() {
    const { communityId } = this.$route.query;
    this.communityId = communityId;
    this.loadCommunityInfo();
  },
  methods: {
    loadCommunityInfo() {
      getCommunityInfo( { VILLAGE_ID: this.communityId } )
      .then( res => {
        if ( res.success ) {
          const data = res.result.data;
          data.xqwl = JSON.parse(data.xqwl);
          console.log(data)
          this.communityInfo = data;
          if ( data.state === '1' ) {
            this.loadDkRecord();
          } else if ( this.$route.path === "/publicline/kdcs/community-dk" && data.state === '2' ) {
            this.$router.replace( {
              path: '/publicline/kdcs/community-page',
              query: { communityId: this.communityId,
                ifBdggz: this.communityInfo.ifBdggz,
                ifSwly: this.communityInfo.ifSwly
              }
            } )
          }
        }
      } )
    },
    loadDkRecord() {
      getCommunityDkRecord({
        VILLAGE_ID: this.communityId
      })
      .then( res => {
        const data = res.result.list;
        console.log("当日打卡记录：", data)
        if ( data.length > 0 ) {
          this.$router.replace( {
            path: '/publicline/kdcs/community-page',
            query: {
              communityId: this.communityId,
              ifBdggz: this.communityInfo.ifBdggz,
              ifSwly: this.communityInfo.ifSwly
            }
          } )
        }
      } )
    }
  }
}
</script>

<style lang="less" scoped>
.community-layout-page {
  background: #FFF;
  // display: flex;
  // flex-direction: column;
}
.content {
  // flex: 1;
  // overflow: auto;
}
.community-info {
  background: #FFF;
  border-bottom: 1px solid #999;
  padding: 10px;
  background: url('~@/assets/imgs/publicline/board/bg-card-fz.png');
  background-size: 110% 110%;
  background-position: center;
  overflow: hidden;
  position: relative;

  .community-name {
    margin-bottom: 8px;
    font-size: 15px;
    font-weight: bold;

    .community-id {
      display: inline-block;
      font-size: 13px;
      padding: 2px 6px;
      background: #409eff;
      border-radius: 4px;
      color: #fff;
      margin-left: 4px;
      font-weight: 500;
    }
    .item-type {
      display: inline-block;
      font-size: 12px;
      padding: 2px 6px;
      background: rgba(203,89,74,0.73);
      border-radius: 4px;
      color: #fff;
      margin-left: 4px;
    }
    .community-type {
      display: inline-block;
      font-size: 13px;
      padding: 2px 6px;
      background: #d063ff;
      border-radius: 4px;
      color: #fff;
      margin-left: 4px;
      font-weight: 500;
    }
  }
  .community-address {
    color: #666;
    font-size: 13px;
    margin-bottom: 10px;
  }
  .community-status {
    position: absolute;
    right: -20px;
    top: 10px;
    width: 100px;
    height: 22px;
    font-size: 13px;
    line-height: 22px;
    border: 1px solid #ccc;
    background: #FFF;
    text-align: center;
    color: #888;
    transform: rotate(34deg);

    &.doing {
      color: #0c85ff;
      border-color: #409eff;
      background: #ecf6ff;
    }
    &.done {
      color: #00ad54;
      border-color: #07c160;
      background: #deffee;
    }
  }
}

.title-line {
  margin-bottom: 5px;
  .title-item {
    font-size: 13px;
    width: 33%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin: 3px 4px;
    color: #555;
    font-weight: bold;
  }
}

.info-line {
  display: flex;
  .info-person {
    width: 33%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin: 2px 4px;
    font-size: 12px;
    color: #444;
  }


  .info-item {
    width: 50%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin: 4px 0;
    padding: 0 10px;
    font-size: 12px;
    color: #444;

    &:first-child {
      border-right: 1px solid #ccc;
      padding-left: 0;
    }

    .info-label {

    }
    .info-value {

    }
  }
}
</style>